package com.demo.Test;

import net.sf.json.JSONObject;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

public class BalanceInquiry {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String info = null;
		try {
			String sss="tc888888";
			System.out.println(TdRaAndCaUtil.HKMD5(sss));
			HttpClient httpclient = new HttpClient();
			PostMethod post = new PostMethod("http://211.162.68.169/user/BalanceInquiry.tran");//
			post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
			post.addParameter("MERNO", "00000000000094");
			post.addParameter("CUSTNO", "00000100000081");
			post.addParameter("PAYACNO", "0000010000008101");
			String str = "MERNO=00000000000094&CUSTNO=00000100000081&PAYACNO=0000010000008101&nqkHwgkRdWy5";
			System.out.println("发送--加密前参数==" + str);
			post.addParameter("SIGNDATA",  TdRaAndCaUtil.HKMD5(str));
			System.out.println("发送--加密后参数==" + TdRaAndCaUtil.HKMD5(str));
			int httpcode = httpclient.executeMethod(post);
			System.out.println("httpcode---->" + httpcode);
			info = new String(post.getResponseBody(), "UTF-8");
			System.out.println("返回信息---->" + info);
			JSONObject jsonObj = JSONObject.fromString(info);
			String MERNO = jsonObj.getString("MERNO");
			String CUSTNO = jsonObj.getString("CUSTNO");
			String PAYACNO = jsonObj.getString("PAYACNO");
			String CASHBALANCE = jsonObj.getString("CASHBALANCE");
			String FROZBALANCE = jsonObj.getString("FROZBALANCE");
			String SIGNDATA = jsonObj.getString("SIGNDATA");
			String RSPCOD = jsonObj.getString("RSPCOD");
			String RSPMSG = jsonObj.getString("RSPMSG");
			System.out.println("RSPCOD==" + RSPCOD);
			System.out.println("返回加密参数==" + SIGNDATA);
			String str2 = "MERNO=" + MERNO + "&CUSTNO=" + CUSTNO + "&PAYACNO=" + PAYACNO + "&CASHBALANCE=" + CASHBALANCE+ "&FROZBALANCE=" + FROZBALANCE+    "&nqkHwgkRdWy5";
			System.out.println("接收--加密前参数==" + str2);
			System.out.println("接收--加密后参数==" + TdRaAndCaUtil.HKMD5(str2));
			if (TdRaAndCaUtil.HKMD5(str2).equals(SIGNDATA)) {
				System.out.println("查询成功+可用余额为"+ Integer.parseInt(CASHBALANCE)*0.01);
				System.out.println("查询成功+冻结余额为"+ Integer.parseInt(FROZBALANCE)*0.01);
			} else {
				System.out.println("查询失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
